package com.d3works.apps.cash.management.service;

import com.d3works.apps.account.db.Invoice;
import com.d3works.apps.account.db.repo.InvoiceLineRepository;
import com.d3works.apps.account.db.repo.InvoiceRepository;
import com.d3works.apps.account.service.app.AppAccountService;
import com.d3works.apps.account.service.config.AccountConfigService;
import com.d3works.apps.account.service.invoice.InvoiceLineService;
import com.d3works.apps.account.service.invoice.InvoiceTermPfpService;
import com.d3works.apps.account.service.invoice.InvoiceTermService;
import com.d3works.apps.account.service.invoice.factory.CancelFactory;
import com.d3works.apps.account.service.invoice.factory.ValidateFactory;
import com.d3works.apps.account.service.invoice.factory.VentilateFactory;
import com.d3works.apps.account.service.move.MoveToolService;
import com.d3works.apps.base.service.PartnerService;
import com.d3works.apps.base.service.alarm.AlarmEngineService;
import com.d3works.apps.base.service.app.AppBaseService;
import com.d3works.apps.base.service.tax.TaxService;
import com.d3works.apps.businessproject.service.InvoiceServiceProjectImpl;
import com.d3works.apps.stock.db.repo.StockMoveRepository;
import com.d3works.apps.supplychain.service.IntercoService;
import com.d3works.exception.D3worksException;
import com.google.inject.Inject;
import com.google.inject.persist.Transactional;

public class InvoiceServiceManagementImpl extends InvoiceServiceProjectImpl {

  protected InvoiceEstimatedPaymentService invoiceEstimatedPaymentService;

  @Inject
  public InvoiceServiceManagementImpl(
      ValidateFactory validateFactory,
      VentilateFactory ventilateFactory,
      CancelFactory cancelFactory,
      AlarmEngineService<Invoice> alarmEngineService,
      InvoiceRepository invoiceRepo,
      AppAccountService appAccountService,
      PartnerService partnerService,
      InvoiceLineService invoiceLineService,
      AccountConfigService accountConfigService,
      MoveToolService moveToolService,
      InvoiceLineRepository invoiceLineRepo,
      InvoiceTermService invoiceTermService,
      InvoiceTermPfpService invoiceTermPfpService,
      AppBaseService appBaseService,
      IntercoService intercoService,
      TaxService taxService,
      StockMoveRepository stockMoveRepository,
      InvoiceEstimatedPaymentService invoiceEstimatedPaymentService) {
    super(
        validateFactory,
        ventilateFactory,
        cancelFactory,
        alarmEngineService,
        invoiceRepo,
        appAccountService,
        partnerService,
        invoiceLineService,
        accountConfigService,
        moveToolService,
        invoiceLineRepo,
        invoiceTermService,
        invoiceTermPfpService,
        appBaseService,
        intercoService,
        taxService,
        stockMoveRepository);
    this.invoiceEstimatedPaymentService = invoiceEstimatedPaymentService;
  }

  @Override
  @Transactional(rollbackOn = {Exception.class})
  public void ventilate(Invoice invoice) throws D3worksException {
    super.ventilate(invoice);
    invoiceEstimatedPaymentService.computeEstimatedPaymentDate(invoice);
  }
}
